<!-- 评论组件 -->
<template>
  <div class="ratingselect">
      <div class="rating-type border-1px">
          <span class="positive" :class="{'active':this.selectType===2}" @click="selected(2)">{{ desc.all }}
          <span class="count" v-if="ratings">{{ ratings.length }}</span>
          </span>
          <span class="positive" :class="{'active':this.selectType===0}" @click="selected(0)">{{ desc.positive }}
            <span class="count" v-if="positives">{{ positives.length }}</span>
          </span>
          <span class="negative" :class="{'active':this.selectType===1}" @click="selected(1)">{{ desc.negetive }}
            <span class="count" v-if="negetives">{{ negetives.length }}</span>
          </span>
      </div>
      <div class="switch" :class="{ 'on':this.onlyContent }">
          <span class="icon-check_circle" @click="commentSelect"></span><span class="text">只看有内容的评价</span>
      </div>
  </div>
</template>

<script>
const POSITIVE = 0;
const NEGETIVE = 1;
// const ALL = 2;
export default {
  data() {
    return {};
  },
  //   props: ["ratings", "selectType", "onlyContent","desc"]
  props: {
    // 评论信息
    ratings: {
      type: Array
    },
    // 分类字段模板
    desc: {
      type: Object,
      default() {
        return {
          all: "全部",
          positive: "满意",
          nagetive: "不满意"
        };
      }
    },
    // 是否选择all/positive/negative
    selectType: {
      type: Number,
      default: 2
    },
    // 是否选择只看有内容的评论
    onlyContent: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 调用父组件food的方法切换selectType
    selected(type) {
      this.$emit("toggleSelected", type);
    },
    // 调用父组件food的方法切换onlyContent
    commentSelect() {
      this.$emit("toggleOnlyContent");
    }
  },
  computed: {
    positives() {
      if (this.ratings) {
        return this.ratings.filter(rating => {
          return rating.rateType === POSITIVE;
        });
      }
    },
    negetives() {
      if (this.ratings) {
        return this.ratings.filter(rating => {
          return rating.rateType === NEGETIVE;
        });
      }
    }
  }
};
</script>
<style lang='less' scoped>
@import "../../common/css/common.less";
.ratingselect {
  font-size: 0;
  .rating-type {
    padding: 12px 0 18px 0;
    margin: 0 18px;
    .border-1px();
    .positive,
    .negative {
      display: inline-block;
      padding: 8px 12px;
      margin-right: 8px;
      background-color: rgba(0, 160, 220, 0.2);
      border-radius: 2px;
      color: rgb(77, 85, 93);
      .font-style(12px,16px);
      &.active {
        color: white;
      }
      .count {
        margin-left: 2px;
        font-size: 8px;
      }
    }
    .positive {
      &.active {
        background-color: rgb(0, 160, 220);
      }
    }
    .negative {
      background-color: rgba(77, 85, 93, 0.2);
      color: rgb(77, 85, 93);
      margin-right: 0;
      &.active {
        background-color: rgb(77, 85, 93);
      }
    }
  }
  .switch {
    padding: 12px 18px;
    color: rgb(147, 153, 159);
    border-bottom: 2px solid rgba(7, 17, 27, 0.1);
    &.on {
      .icon-check_circle {
        color: #00c850;
      }
    }
    .icon-check_circle {
      display: inline-block;
      .font-style(24px,24px);
      margin-right: 4px;
    }
    .text {
      display: inline-block;
      .font-style(12px,24px);
      vertical-align: top;
    }
  }
}
</style>